package com.ccp.dev.qbdms.service;

import com.ccp.dev.core.basic.web.query.QueryFilter;
import com.ccp.dev.form.service.impl.ScriptImpl;
import com.ccp.dev.qbdms.consts.ZhiLiangConst;
import com.ccp.dev.qbdms.model.WQbdReportTemplate;
import com.ccp.dev.qbdms.model.vo.ModelQualityStatisticsParamVo;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;

import com.ccp.dev.qbdms.util.BaseUtil;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.stereotype.Service;

/**
 * ClassDescribe:
 *
 * @author :milihao
 * @date :2019-07-23 Since:1
 */
@Service
public class MilitaryTradeQualityService {

	@Resource
	private WQbdReportTemplateService wQbdReportTemplateService;
	@Resource
	public ScriptImpl scriptimpl;

	public List<Map<String, Object>> getChartData(
			ModelQualityStatisticsParamVo modelQualityStatisticsParamVo, QueryFilter queryFilter) {
		ZhiLiangConst.addQueryFilter(queryFilter);
		List<Map<String, Object>> list = new ArrayList<>();
		Map<String, Object> querymap = new HashMap<>();
		querymap.put("reportStatus", queryFilter.get("reportStatus"));
		querymap.put("secret", scriptimpl.getCurrentUser().getPrivacyLevel());
		querymap.put("belongdeptname", BaseUtil.getCurrentTenOrgCodePath() + "%");
		WQbdReportTemplate wQbdReportTemplate = new WQbdReportTemplate();
		Date startTime = new Date();
		Date endTime = new Date();
		try {
			if (("aydtj").equals(modelQualityStatisticsParamVo.getStatisticalMethods())) {
				startTime = DateUtils.parseDate(modelQualityStatisticsParamVo.getBeginTime(), "yyyy-MM");
				endTime = DateUtils.parseDate(modelQualityStatisticsParamVo.getEndTime(), "yyyy-MM");
			} else {
				startTime = DateUtils.parseDate(modelQualityStatisticsParamVo.getBeginTime(), "yyyy");
				endTime = DateUtils.parseDate(modelQualityStatisticsParamVo.getEndTime(), "yyyy");
			}

		} catch (ParseException e) {
			e.printStackTrace();
		}
		wQbdReportTemplate.setMilitaryTradeQualityStart(startTime);
		wQbdReportTemplate.setMilitaryTradeQualityEnd(endTime);
		wQbdReportTemplate
				.setMilitaryTradeQuality(modelQualityStatisticsParamVo.getStatisticalMethods());
		list.add(wQbdReportTemplateService
				.getProblemResetHistogramDataByModelType(wQbdReportTemplateService.CHART_BAR,
						wQbdReportTemplate,
						querymap));
		list.add(wQbdReportTemplateService
				.getProblemResetHistogramDataByModelType(wQbdReportTemplateService.TABLE,
						wQbdReportTemplate, querymap));
		return list;
	}
}
